<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>Deploy Manager WebApp's Test Page</title>
	</head>
	
	<style>
	
		div {
			border: 1px black solid; 
			padding: 5px;
			margin-bottom: 25px;
		}
		
		p {
			font-weight: bold; 
			vertical-align: middle; 
			text-align: center;
		}
	
	</style>

	<body>
		
		<h2>Deploy Manager WebApp's Test Page</h2>

		<div>
			<p>AJAX login, Application Managed Security</p>
			Username: <input id="username" type="text" name="username"><br/>
			Password: <input id="password" type="password" name="password"><br/>
			<input type="button" value="Login" onclick="sendLoginRequest();">
			<label id="result"></label>
			<br/>
			<input type="button" value="Already logger?" onclick="sendAlreadyLoggerRequest();">
			<br/>
			<input type="button" value="Logout" onclick="sendLogoutRequest();">
		</div>
		
		<div>
			<p><a href="/deploymanager/services/configtree">Root config tree</a></p>
			
			<p>Per creare le cartelle sotto la configtree usare il METODO HTTP MKCOL con l'uri da creare, ruolo amministratore </p>
			
			<p>Per cancellare le cartelle/file sotto la configtree usare il METODO HTTP DELETE con l'uri da cancellare, ruolo amministratore </p>
			
			<p>Per scrivere una nuova configurazione usare il METODO HTTP PUT con l'uri del file che si desidera creare, inviando come contenuto della PUT il contenuto del file </p>
			
			<p>Per sovrascrivere una configurazione usare il METODO HTTP POST con l'uri del file che si desidera sovrascrivere, inviando come contenuto della POST il nuovo contenuto </p>
			
			<p> Esempi a linea di comando (occhio che quando l'autenticazione è abilitata non funzionano perchè bisogna passare il login cookie)
				<pre>
					curl -X MKCOL http://localhost:8080/deploymanager/services/configtree/cazcaz
					curl -X PUT http://localhost:8080/deploymanager/services/configtree/cazcaz/sdfd.txt -d "Testo dentro il file"
					curl -X POST http://localhost:8080/deploymanager/services/configtree/cazcaz/sdfd.txt -d "Nuovo testo dentro il file"
					curl -X DELETE http://localhost:8080/deploymanager/services/configtree/cazcaz
				</pre>
			</p>
		</div>
		
		
		<script type="text/javascript">
		
			var httpRequest;
			var result = document.getElementById("result");
			var username = document.getElementById("username");
			var password = document.getElementById("password");
	
			function sendLoginRequest() {
	
				if (window.XMLHttpRequest) { // Mozilla, Safari, ...
					httpRequest = new XMLHttpRequest();
				} else if (window.ActiveXObject) { // IE
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
	
				httpRequest.onreadystatechange = function () {
					if (httpRequest.readyState == 4) {
						if (httpRequest.status == 200) {
							result.innerHTML = "Logged!";
						} else if (httpRequest.status == 401) {
							result.innerHTML = "Unauthorzed!";
						} else {
							alert('There was a problem with the request.');
						}
					}
				};
				httpRequest.open('POST', '/deploymanager/services/login', true);
				httpRequest.setRequestHeader("Accept", "application/json");
				httpRequest.send("username="+username.value+"&password="+password.value);
			}
			
			function sendLogoutRequest() {
				
				if (window.XMLHttpRequest) { // Mozilla, Safari, ...
					httpRequest = new XMLHttpRequest();
				} else if (window.ActiveXObject) { // IE
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
	
				httpRequest.onreadystatechange = function () {
					if (httpRequest.readyState == 4) {
						if (httpRequest.status == 204) {
							result.innerHTML = "Logged OUT!";
						} else {
							alert('There was a problem with the request.');
						}
					}
				};
				httpRequest.open('GET', '/deploymanager/services/logout', true);
				httpRequest.send();
			}
			
			function sendAlreadyLoggerRequest() {
			
				if (window.XMLHttpRequest) { // Mozilla, Safari, ...
					httpRequest = new XMLHttpRequest();
				} else if (window.ActiveXObject) { // IE
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}
	
				httpRequest.onreadystatechange = function () {
					if (httpRequest.readyState == 4) {
						if (httpRequest.status == 200) {
							result.innerHTML = "Already logged!";
						} else if (httpRequest.status == 401) {
							result.innerHTML = "Not logged!";
						} else {
							alert('There was a problem with the request.');
						}
					}
				};
				httpRequest.open('POST', '/deploymanager/services/login', true);
				httpRequest.send();
				
			}
			
		</script>
		
	
<!-- 		<hr/> -->
<!-- 		<h3>Get Environment (and root environment) (HTTP GET)</h3> -->
<!-- 		<a href="manager/config">here</a> -->
		
<!-- 		<hr/> -->
<!-- 		<h3>Create Environment (HTTP PUT)</h3><br/> -->
<!-- 		Send PUT to manager/config/ENV1/SUBENV2... -->
<!-- 		(curl -X PUT --user user:password http://example.com) -->
<!-- 		<hr/> -->

<!-- 		<h3>Delete Environment (HTTP DELETE)</h3><br/> -->
<!-- 		Send DELETE to manager/config/ENV1/SUBENV2... -->
<!-- 		(curl -X DELETE --user user:password http://example.com) -->
<!-- 		<hr/> -->

<!-- 		<hr/> -->
<!-- 		<hr/> -->
<!-- 		<h3>Create VirtualHost (HTTP POST)<br/> -->
<!-- 		Send POST to manager/config/ENV1/SUBENV2... with the body of VirtualHost and ContentType="" -->
<!-- 		<form action="manager/configuration/envname/vhname" method="post"> -->
<!-- 			<input type="text" name="name" value="vhname"></input> -->
<!-- 			<input type="submit" /><br/> -->
<!-- 		</form> -->
<!-- 		<hr/> -->

<!-- 		<h3>Get VirtualHost (HTTP GET)<br/> -->
<!-- 		<a href="manager/configuration/envname/vhname">here</a> -->
<!-- 		<hr/> -->

<!-- 		<h3>Update Environment (HTTP GET)<br/> -->
<!-- 		<form action="manager/configuration/envname/vhname" method="put"> -->
<!-- 			<input type="submit" /><br/> -->
<!-- 		</form> -->
<!-- 		<hr/> -->

<!-- 		<h3>Delete Environment (HTTP POST)<br/> -->
<!-- 		<form action="manager/configuration/envname/vhname" method="delete"> -->
<!-- 			<input type="submit" /><br/> -->
<!-- 		</form> -->
<!-- 		<hr/> -->
<!-- 		<hr/> -->
		
	</body>
	
</html>